package org.fast.develop.logicflow.persistence.domain;

import org.fast.develop.logicflow.persistence.jpa.entity.LogicDefinitionEntity;
import org.fast.develop.logicflow.persistence.jpa.repository.LogicDefinitionJpaRepository;
import org.fast.develop.logicflow.repository.domain.definition.LogicDefinition;
import org.fast.develop.logicflow.repository.domain.definition.LogicDefinitionRepository;


/**
 * @author 莫寅
 * @createTime 2022-12-20 00:01
 * @desc：
 */
public class LogicDefinitionRepositoryImpl extends BaseLogicRepository<LogicDefinition<String>, String> implements LogicDefinitionRepository {

    private LogicDefinitionJpaRepository logicDefinitionJpaRepository;

    public LogicDefinitionRepositoryImpl(LogicDefinitionJpaRepository jpaRepository) {
        super(jpaRepository);
        this.logicDefinitionJpaRepository = jpaRepository;
    }

    @Override
    protected Class<? extends LogicDefinition<String>> getEntityClass() {
        return LogicDefinitionEntity.class;
    }

    @Override
    public LogicDefinition findByMaxVersion(String key) {
        return logicDefinitionJpaRepository.findTopByAndKeyOrderByVersionDesc(key);
    }
}
